#include <string.h>
#include "Student.h"
Student::Student()
	{	
	strcpy((*this).nume,"a");
	strcpy((*this).pren,"b");
	(*this).nr_matr=34;	
	}
Student::Student(char s[10],char p[10],int n)
	{
	strcpy((*this).nume,s);
	strcpy((*this).pren,p);
	(*this).nr_matr=n;	
	}
void Student::setNume(char s[10])
	{
	strcpy((*this).nume,s);
	}
void Student::setPren(char s[10])
	{
	strcpy((*this).pren,s);
	}
void Student::setNrMat(int s)
	{
	(*this).nr_matr=s;
	}
char* Student::getNume()
	{
	return (*this).nume;
	}
char* Student::getPren()
	{
	return (*this).pren;
	}
int Student::getNrMat()
	{
	int n;
	n=(*this).nr_matr;
	return n;
	}
Student Student::operator=(Student B)
	{
	strcpy((*this).nume,B.nume);
	strcpy((*this).pren,B.pren);
	(*this).nr_matr=B.nr_matr;
	return B;
	}
ostream& operator<<(ostream& cout,Student B)
	{
	cout<<B.getNume()<<" "<<B.getPren()<<" - "<<B.getNrMat()<<endl;
	return cout;
	}
void listaSt::adauga(Student A)
	{
		(*this).M[n]=A;
		n++;
		(*this).sorteaza();
	}
listaSt::listaSt()
	{
	Student A;
	(*this).M[n]=A;	
	}
void listaSt::sterge(char nume[10])
	{
	int m=0;
	m=(*this).caut(nume);
	if(m==31)
		{
		std::cout<<"\n\tNumele dat nu corespunde cu nici un nume sau prenume al unui student deja existent!\n";		
		}
	else
		{
		for(int i=m-1;i<n-1;i++)
			(*this).M[i]=(*this).M[i+1];		
		n--;
		}
	}
void listaSt::sterge(int b)
	{
	int m=0;
	while((*this).M[m].getNrMat()!=b)
		m++;
	if(m==n)
		std::cout<<"\n\tNu s-a gasit nici un student al carui numar matricol sa corespunda numarului dat!\n";
		else
			{			
			for(int i=m;i<n-1;i++)
				(*this).M[i]=(*this).M[i+1];
			}	
	n--;
	}
int listaSt::caut(char b[10])
	{
	int gasit=0,j=31,i;
	for(i=0;i<=n&&gasit==0;i++)
		if( strcmp (b, (*this).M[i].getNume()) ==0 || strcmp ( b , (*this).M[i].getPren() )==0 )	
			gasit=1;
	if(gasit==1)
		return i;
	else
		return j;
	}
int listaSt::cauta(char b[10])
	{
	int gasit=0,j=31,i;
	for(i=0;i<=n&&gasit==0;i++)
		if( strcmp (b, (*this).M[i].getNume()) ==0 || strcmp ( b , (*this).M[i].getPren() )==0 )	
			gasit=1;
	if(gasit==1)
		std::cout<<"\n\tStudentul a fost gasit pe pozitia "<<i-1<<" cu nr matricol : "<<(*this).M[i].getNrMat()<<"\n";
	else
		std::cout<<"\n\tStudentul nu a fost gasit!\n";
	if(gasit==1)
		return i;
	else
		return j;
	}
int listaSt::cauta(int b)
	{
	int gasit=0,j=31,i;
	for(i=0;i<n&&gasit==0;i++)
		if((*this).M[i].getNrMat()==b)
			gasit=1;
	if(gasit==1)
		std::cout<<"\n\tStudentul a fost gasit pe pozitia "<<i-1<<" cu numele : "<<(*this).M[i].getNume()<<" si prenumele : "<<(*this).M[i].getPren()<<"!!";
	else
		std::cout<<"\n\tStudentul nu a fost gasit!\n";
	if(gasit==1)
		return i;
	else
		return j;	
	}
void listaSt::sorteaza()
	{
	Student aux;
	for(int j=0;j<n;j++)
		for(int k=0;k<n;k++)
			{
			if( strcmp( (*this).M[j].getNume(),(*this).M[k].getNume() ) <0)
				{
				aux=(*this).M[j];
				(*this).M[j]=(*this).M[k];
				(*this).M[k]=aux;				
				}					
			}	
	}
void listaSt::modificaNume()
	{
	int m;
	char s[30],p[30];
	std::cout<<"\nIntroduceti numele care doriti sa-l modificati : ";cin>>s;
	m=(*this).caut(s);
	if(m==31)
		std::cout<<"\n\tNumele respectiv nu a fost gasit!.";
	else
		{
		m--;
		std::cout<<"\nIntroduceti noul prenume : ";cin>>p;
		(*this).M[m].setNume(p);		
		}
	}
void listaSt::modificaNr()
	{
	int m,p;
	char s[10];
	std::cout<<"\nIntroduceti numele studentului al carui numar matricol doriti sa-l modificati : ";cin>>s;
	m=(*this).caut(s);
	if(m==31)
		std::cout<<"\n\tNumele respectiv nu a fost gasit!.";
	else
		{
		m--;
		std::cout<<"\nIntroduceti noul numar matricol : ";cin>>p;
		(*this).M[m].setNrMat(p);		
		}
	}
void listaSt::modificaPren()
	{
	int m;
	char s[30],p[30];
	std::cout<<"\nIntroduceti numele studentului al carui prenume doriti sa-l modificati : ";cin>>s;
	m=(*this).caut(s);
	if(m==31)
		std::cout<<"\n\tNumele respectiv nu a fost gasit!.";
	else
		{
		m--;
		std::cout<<"\nIntroduceti noul nume : ";cin>>p;
		(*this).M[m].setPren(p);		
		}
	}
ostream& operator<<(ostream& cout,listaSt B)
	{
	cout<<"\n\t\t  Student           Nr. Matricol"<<endl;
	for(int i=0;i<n;i++)
	cout<<"\n\t\t"<<B.M[i].getNume()<<" "<<B.M[i].getPren()<<"\t\t "<<B.M[i].getNrMat();
	cout<<endl;
	return cout;	
	}

